|
|
|
|
|
|
|
To determine whether the form has shrunk, you can keep track of its width and height. When you receive a Resize event, compare the new and old widths and heights to see if either dimension has gotten larger. If so, the Resize event will be followed by a Paint event, so you do not need to redraw the form yet. Otherwise, the form has shrunk. If you want to rearrange the form to take into account its new size, you should do so. |
|
|
|
|
|
|
|
|
Finally, in most applications, there is no reason to redraw the form or even recompute its drawing parameters when the form is minimized. Because the user cannot see the form anyway, any effort you spend at this point is wasted. When the form is restored, its size will probably be the same as it was before the form was minimized, so you would only have to recompute the drawing parameters again. |
|
|
|
|
|
|
|
|
You can check whether a form is minimized using the form's WindowState property. If, during a Resize event, the form's WindowState has the value vbMinimized, the form is minimized and you can exit the event handler. |
|
|
|
|
|
|
|
|
The following code shows Paint and Resize events that manage these interactions. This code assumes the two subroutines CalculateParameters and DrawForm compute the drawing parameters and redraw the form. |
|
|
|
 |
|
|
|
|
Private Sub Form_Paint()
' Always redraw when we get a Paint event. DrawForm
End Sub
Private Sub Form_Resize()
Static wid As Single
Static hgt As Single
' If we're minimized, do nothing. If WindowState = vbMinimized Then Exit Sub
' If the size has changed, recalculate the
' drawing parameters. This will not happen if
' we are being restored after being minimized. If Width <> wid Or Height <> hgt Then CalculateParameters
' If we are shrinking, redraw now. If we are not shrinking,
' leave the drawing to the Paint event handler. If Not ((Width >= wid) And (Height >= hgt)) Then DrawForm
' Save the new width and height. wid = Width
hgt = Height
End Sub |
|
|
|
|
|
|
|
|
Example program Resize, shown in Figure 1.17 uses this code to draw a smiley face. Whenever the form is resized, the program recalculates drawing parameters so that the face is as large as possible. The form contains two labels that tell you how many times it has calculated the drawing parameters and redrawn the picture. |
|
|
|
|
|